﻿@model Ducu.SRV.ViewModel.Task.HistoryListItemModel
@using Global.Core.ExtensionMethod
@using Ducu.GLB.Global
<div class="panel panel-default">
    <div class="panel-heading">
        @Html.Partial("Shared/_Day", Model.Title)
        <span style="margin-left: 8px;">@Model.Title.CompleteDate.ToChineseDate()</span>
    </div>
    <div class="panel-body">
        @if (!Model.History.IsNullOrEmpty())
        {
            for (int i = 0; i < Model.History.Count; i++)
            {
                var history = Model.History[i];

                string className = i % 2 == 0 ? "pull-left" : "pull-right";

                <div class="@className" style="clear:both;">
                    <p>
                        <a href="/User/Profile/@history.Executor.Id">@history.Executor.Name</a>
                        @history.Status.ToTaskHistory()
                    </p>
                    @if (!string.IsNullOrEmpty(history.MyComment))
                    {
                        <p>
                            留言：@history.MyComment
                        </p>
                    }
                    <small>时间：@history.CreateTime.ToChinese()</small>
                    @if (i < Model.History.Count - 1)
                    {
                        <hr />
                    }
                </div>
            }
            if (Model.ShowReply)
            {
                <div id="reply-show" style="clear:both; margin-bottom: 30px; position: relative; top:20px;">
                </div>
                using (Ajax.BeginForm("_Reply", "Task", new { id = Model.TaskId }, new AjaxOptions
                {
                    HttpMethod = "POST",
                    InsertionMode = InsertionMode.InsertAfter,
                    UpdateTargetId = "reply-show",
                    OnBegin = "validateForm",
                    OnComplete = "emptyTextInput",
                    OnFailure = "replyFailed"
                }))
                {
                    @Html.HiddenFor(m => m.TaskId)
                    <div class="form-group">
                        @Html.TextAreaFor(m => m.Reply.Content, new { @class = "form-control", rows = "3", placeholder = "给个回复吧？" })
                        <span id="reply-empty-error" style="color: red;"></span> @*ajax form: model validation doesn't work*@
                        <br />
                        <input type="submit" class="btn btn-primary btn-sm" value="提交" />
                        @if (Model.ApplyAccept)
                        {
                            <label class="checkbox-inline" style="margin-left:15px;"> @Html.CheckBoxFor(m => m.ApplyAccept) 请求再次验收</label>
                        }
                    </div>
                }
            }
            if (Model.CanAccept)
            {
                <div id="reply-show" style="clear:both; margin-bottom: 30px; position: relative; top:20px;">
                </div>
                <a href="/Task/Accept/@Model.PlanId?taskId=@Model.TaskId" class="lead"><span class="glyphicon glyphicon-share-alt"></span> 去该任务</a>
            }
        }
    </div>
    <script>
        function emptyTextInput(){
            $("#@Html.IdFor(m=>m.Reply.Content)").val("");
        }
        function validateForm() {
            //if ($("#Reply_Content").val() == "") {
            //    $("#reply-empty-error").text("* 回复不能为空").show();
            //    return false;
            //}
        }
        function replyFailed() {
            alert("很抱歉，回复消息时出现异常。请检查是否填写了回复信息，或稍后再试。如问题反复出现，请联系我们，我们将非常感谢你的反馈和意见。");
        }
    </script>
</div>
